package org.ns.summer.classpath.scan.factory;

import java.util.List;

import org.ns.summer.classpath.scan.ScanFile;
import org.ns.summer.classpath.scan.ScanFileExecute;
import org.ns.summer.classpath.scan.impl.BasicScanFileExecute;
import org.ns.summer.classpath.scan.parse.JarSuffixScanFileParse;
/**
 * @author 张星宇
 *
 * @email m.vip@qq.com
 */
public class DirAndJarScanFileFactory {
	
	private static ScanFileExecute dirAndJarscanFileExecute = new BasicScanFileExecute();
	private static ScanFileExecute dirScanFileExecute = new BasicScanFileExecute();
	static{
		// 设置 后缀为 jar 的解析器
		dirAndJarscanFileExecute.addSuffixScanFileParse("jar", new JarSuffixScanFileParse());
	}
	public static ScanFileExecute getScanFileExecute() {
		return dirAndJarscanFileExecute;
	}
	/** 扫描当前路径下的所有文件与jar
	 * 
	 * @param scanRootPath
	 * @return
	 */
	public static List<ScanFile> scan(String scanRootPath){
		return getScanFileExecute().execScan(scanRootPath);
	}
	/** 只扫描文件夹下的,不包含jar
	 * 
	 * @param scanRootPath
	 * @return
	 */
	public static List<ScanFile> scanOnlyDir(String scanRootPath){
		return dirScanFileExecute.execScan(scanRootPath);
	}
//	public static List<ScanFile> scanOnlyDirReal(String scanRootPath){
//		List<ScanFile> files = dirScanFileExecute.execScan(scanRootPath);
//		realClassName(files);
//		return files;
//	}
//	/** 获得 真实的信息
//	 * 
//	 * @param scanRootPath
//	 * @return
//	 */
//	public static List<ScanFile> scanReal(String scanRootPath){
//		List<ScanFile> files = getScanFileExecute().execScan(scanRootPath);
//		realClassName(files);
//		return files;
//	}
	
//	/** 填充真实的className
//	 * 
//	 * @param files
//	 * @return
//	 */
//	public static List<ScanFile> realClassName(List<ScanFile> files){
//		for (ScanFile scanFile : files) {
//			try (ScanFileInputStream in = new ScanFileInputStream(scanFile)){
//				ClassReader classReader = new ClassReader(in);
//				String className = classReader.getClassName().replace('/', '.');
//				ScanFile.updateClassName(scanFile, className);
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//		}
//		return files;
//	}
}
